package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.Util.DateUtil;

public class ButtonActivity extends AppCompatActivity {

    private TextView tv1;
    private TextView btn2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button);
        tv1 = findViewById(R.id.tv);
        btn2 = findViewById(R.id.btn2);
        btn2.setOnClickListener(new myOnClickedListener());
        btn2.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return false;//返回false表示将该事件继续传递到父控件，返回true表示在这里就将该事件处理完成了，不继续向上传递事件
            }
        });
    }
    public void myOnClicked(View view)//参数就是锁点击的按钮
    {
        String ret=String.format("%s,宁点击了按钮%s",DateUtil.getTimeStr(),((Button)view).getText());
        tv1.setText(ret);
    }
    private class  myOnClickedListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            String ret=String.format("%s,宁点击了按钮%s",DateUtil.getTimeStr(),btn2.getText());
            tv1.setText(ret);
        }

    }
}
